<!-- Web Upload Account search PHP File -->
<!-- Reveions History ...
	Rev 1.00 at 2015/06/08 by Max Yin:
		1. First time create
	Rev 1.01 at 2015/07/08 by Max Yin:
		1. 由標楷體, 改成新細明體
-->
<html>
	<body background="pic/background_06.gif">
	<head>
		<font face="新細明體,time new roman,Arial">
		<meta charset="UTF-8">
	</head>
	<body>
		<center>
			<font size="5" color="#0000FF"><b>--- 帐号,查询结果 ---</b></font><br>
			<hr>
			<?php
				require_once('class_package/common.php');
				$search_username = $_POST['accout_username'];
				
				// To check user name & password limit ...
				if ( $search_username == '' ) {
					echo "<script>alert('输入的栏位中, 不能为空值, 请重新输入!!');history.go(-1);</script>";
					exit();
				}
				
				$str = strtolower($search_username);
				$show_num = 0;
				if ( $str == 'all' ) {
					setcookie('seach_user',$str);
					// To search all table ... 
					$db_select    = Sql_Account::sql_db;
					$db_table     = Sql_Account::sql_table;
					$table_name1  = Sql_Account::table_name1;
					$conn         = '';
					$sql_cmd      = '';
					$rows         = 0;
					$result       = '';
					
					// Check connection
					$conn = mysqli_connect(html::sql_login_host,html::sql_login_user,html::sql_login_pass,$db_select);
					if ( mysqli_connect_errno($conn) ) { 
						echo "<script>alert('MySql资料库连接失败,请联系开发人员,并查明原因...');history.go(-1);</script>";
						exit();
					}
					mysqli_set_charset($conn,'set names utf8');
					
					// 要是字段是字符型，必须要用''（单引号）括起来，要是数值型，若中间有空格，可以用''（单引号）括起来; 若没有空格，也可以不用...
					// SELECT * FROM `account_member` ORDER BY `username` DESC
					$sql_cmd = "SELECT * FROM `$db_table` ORDER BY `$table_name1` ASC";
					$result = mysqli_query($conn,$sql_cmd);	// 透过 execute_query 对象实例完成查询
					if ( !$result ) { 
						mysqli_close($conn);				// 关闭资料库
						echo "<script>alert('MySql资料库搜寻失败,请跟开发人员查明原因...');history.go(-1);</script>";
						exit();
					}
					
					$rows = mysqli_num_rows($result);		// 返回结果集中栏位的数量。
					if ( $rows == 0 ) { 
						mysqli_close($conn);				// 关闭资料库
						echo "<script>alert('MySql资料库获取栏位数失败...');history.go(-1);</script>";
						exit();
					}
					
					echo '<br>
					<table border="2" width="70%">
						<tr bgcolor="#70DB93">
							<th>#</th>
							<th>User Name</th>
							<th>Password</th>
							<th>Create Date/Time</th>
							<th>Create By</th>
							<th>IsAdmin</th>
							<th>Delete</th>
							<th>Update</th>
						</tr>';
					
					while ( $getArray = mysqli_fetch_array($result,MYSQLI_ASSOC) ) {
						$show_num++;
						$get_username    = $getArray['username'];
						$get_password    = $getArray['password'];
						$get_create_date = $getArray['create_date'];
						$get_create_by   = $getArray['create_by'];
						$isadmin   = $getArray['Admin'];
						$webul_delete    = "webul_account_delete.html?seach_user=$get_username";
						$webul_update    = "webul_account_update.html?seach_user=$get_username";
						$admin='N';
						if($isadmin==1){
							$admin='Y';
						}
						echo "
							<tr>
								<th>$show_num</th>
								<th>$get_username</th>
								<th>$get_password</th>
								<th>$get_create_date</th>
								<th>$get_create_by</th>
								<th>$admin</th>
								<th><a href=$webul_delete>删 除</a></th>
								<th><a href=$webul_update>修 改</a></th>
							</tr>";
					}
					echo '</table><br>';
					mysqli_free_result($result);			// 释放 MySQL $result
					mysqli_close($conn);					// 关闭资料库
				} else {
					// To search the account user name and password from MySQL then show to table ...
					$get_seach_result = account_search_result($search_username);
					if ( !is_array($get_seach_result) ) {
						echo "<script>alert('查无此帐号? 请检查后,重新输入...');history.go(-1);</script>";
						exit();
					}
					$get_username    = AnalyzeMySqlStr($get_seach_result,'username');
					setcookie("seach_user",$get_username);
					$get_password    = AnalyzeMySqlStr($get_seach_result,'password');
					$get_create_date = AnalyzeMySqlStr($get_seach_result,'create_date');
					$get_create_by   = AnalyzeMySqlStr($get_seach_result,'create_by');
					$isadmin   = AnalyzeMySqlStr($get_seach_result,'Admin');
					$webul_delete    = "webul_account_delete.php";
					$webul_update    = "webul_account_update.html";
					$show_num++;
					$admin='N';
					if($isadmin==1){
						$admin='Y';
					}
					
					// To show tabels ...
					echo '
						<br>
						<table border="2" width="70%">
							<tr bgcolor="#70DB93">
								<th>#</th>
								<th>User Name</th>
								<th>Password</th>
								<th>Create Date/Time</th>
								<th>Create By</th>
								<th>IsAdmin</th>
								<th>Delete</th>
								<th>Update</th>
							</tr>';
					echo "
						<tr>
							<th>$show_num</th>
							<th>$get_username</th>
							<th>$get_password</th>
							<th>$get_create_date</th>
							<th>$get_create_by</th>
							<th>$admin</th>
							<th><a href=$webul_delete>删 除</a></th>
							<th><a href=$webul_update>修 改</a></th>
						</tr>";
					echo '</table><br>';
				}
			?>
		</center>
	</body>
</html>

